package com.glory.dgcpcpda.adapter;

import android.annotation.SuppressLint;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.entity.EqpDataAcquisitionBean;

import java.util.List;

public class EqpDataAcquistionAdapter extends BaseQuickAdapter<EqpDataAcquisitionBean.EDCSETLISTDTO.EDCSETITEMLINELISTDTO, BaseViewHolder> {

    private boolean showEnable;
    private String itemName = "";
    private int num = 1;
    public EqpDataAcquistionAdapter(@Nullable List<EqpDataAcquisitionBean.EDCSETLISTDTO.EDCSETITEMLINELISTDTO> data,boolean showEnable) {
        super(R.layout.adapter_eqp_data_acquisition, data);
        this.showEnable = showEnable;
    }



    @Override
    protected void convert(BaseViewHolder helper, EqpDataAcquisitionBean.EDCSETLISTDTO.EDCSETITEMLINELISTDTO item) {


        helper.setText(R.id.data_name,item.getNAME());
        helper.setText(R.id.data_info,item.getDESCRIPTION());
        helper.setText(R.id.data_usl,item.getUSL());
        if (itemName == ""){
            itemName = item.getNAME();
            helper.setText(R.id.num,String.valueOf(num));
            num++;
        }else {
            if (itemName.equals(item.getNAME())){
                helper.setText(R.id.num,String.valueOf(num));
                num++;
            }else {
                itemName = item.getNAME();
                num = 1;
                helper.setText(R.id.num,String.valueOf(num));
                num++;
            }
        }
        helper.setGone(R.id.eqpEditTextRemarks,true);
        EditText et = helper.getView(R.id.eqpEditTextRemarks);
//        if (item.getEDCTYPE().equals("NUM")){
//            et.setInputType(InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_NUMBER_FLAG_DECIMAL);
//        }
        if (et.getTag() instanceof TextWatcher) {
            et.removeTextChangedListener((TextWatcher) et.getTag());
        }
        et.setText(item.getVALUE());
        et.setEnabled(showEnable);
        TextWatcher watcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setVALUE(s.toString());
            }
        };
    }
}
